package com.ccc.demoboot.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccc.demoboot.dao.RolemidmenuMapper;
import com.ccc.demoboot.pojo.Rolemidmenu;
import com.ccc.demoboot.service.RolemidmenuService;

/**
 * @Author wz
 * @Date 2024/5/20 11:41
 * @PackageName:com.ccc.demoboot.service
 * @ClassName: RolemidmenuServiceImpl
*/
@Service
public class RolemidmenuServiceImpl extends ServiceImpl<RolemidmenuMapper, Rolemidmenu> implements RolemidmenuService{


    @Override
    public int updateRole(Integer roleid, List list) {
        //根据角色id删除对应的菜单集合
        QueryWrapper<Rolemidmenu> rolemidmenuQueryWrapper = new QueryWrapper<>();
        rolemidmenuQueryWrapper.eq("roleid",roleid);
        this.baseMapper.delete(rolemidmenuQueryWrapper);
        //根据角色id增加多条对应的菜单id
        for (Object o : list) {
            Rolemidmenu rolemidmenu = new Rolemidmenu();
            rolemidmenu.setRoleid(roleid);
            rolemidmenu.setMenuid((Integer) o);
            this.baseMapper.insert(rolemidmenu);
        }
        return 1;
    }
}
